<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
	function showProductAttributeByProductTypeId(productTypeId){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/shopProduct/getProductAttributeAndValueList.sjson",
            data: {productTypeId:productTypeId},
            success: function(data){
                var productAttrList = data.productAttributeList;
                $("#attrTable").html("");
                if (productAttrList != "" && productAttrList != null) {
					var htmlAttrStr = "";
					var isValidCount=1;/**有效可显示的属性个数计数器，用于换行计算**/
					for (var i = 0; i < productAttrList.length; i++) {
						var productAttrValueList = productAttrList[i].shopProductAttributeValueList;
						if (productAttrValueList != ""&& productAttrValueList != null) {
							/**如果tmp不为空 则添加对应的属性及属性值数据**/
							if(isValidCount%2==1){/**表示第2个还是换行，一行2个**/
								htmlAttrStr += "<tr>";
							}
							htmlAttrStr += "<td width='200px' class='toright_td'>" + productAttrList[i].name + ":</td>" +
								"<input type='hidden' name='productAttrValueVoList[" + i + "].name' value='"+productAttrList[i].productAttrId+ "'/>";
							if(i==productAttrList.length-1 && isValidCount%2==1){/**判断最后一个是奇数还是偶数，是奇数进行样式处理**/
								htmlAttrStr += "<td width='200px' class='toleft_td' style='border-right: none;'>";
							}else{
								htmlAttrStr += "<td width='200px' class='toleft_td'>";
							}
							htmlAttrStr += "<div class='form-group'>"+
								"<select class='form-control input-sm' id='productAttrList_" + productAttrList[i].productAttrId + "' name='productAttrValueVoList[" + i + "].value'>";
							htmlAttrStr += "<option style='width:80px ' value='' selected>请选择</option>";
							for (var j = 0; j < productAttrValueList.length; j++) {
								htmlAttrStr += "<option style='width:80px ' value='" + productAttrValueList[j].attrValueId + "'>"
									+ productAttrValueList[j].attrValueName + "</option>";
							}
							htmlAttrStr += " </select></div></td>";

							if(i==productAttrList.length-1 && isValidCount%2==1){/**判断最后一个是奇数还是偶数，是奇数进行样式处理**/
								htmlAttrStr += " <td class='toleft_td' colspan='2' style='border-left: none;'></td>";
							}

							if(isValidCount%2==0){/**表示第2个还是换行，一行2个**/
								htmlAttrStr += " </tr>";
							}
							isValidCount++;
						}
					}
					$("#attrTable").html(htmlAttrStr);
                } else {
                    $("#attrTable").empty().html("<tr><td>该分类下无商品扩展属性信息</td></tr>");
                }
            }
        });
	}

    /**初始化商品扩展属性信息**/
	function initProductAttributeInfo(productTypeId,productAttributeIndexList){
        showProductAttributeByProductTypeId(productTypeId); /**先初始化产品分类对应的属性信息**/
        for(var i=0;i<productAttributeIndexList.length;i++){
            var productAttributeIndex=productAttributeIndexList[i];
            $("#productAttrList_"+productAttributeIndex.productAttrId).find("option[value='"+productAttributeIndex.attrValueId+"']").attr("selected",true);
		}
	}
</script>


<div style="margin-top: 10px;">
	<table id="attrTable"  class="addOrEditTable table-bordered table" style="width:100%;">
		<tr id="noAttrTr"><td>无商品扩展属性信息，请检查“基本信息”标签中是否已选择商品分类</td></tr>
	</table>
</div>